package com.hua.designpattern.j2eepattern.transferobject;

import java.util.ArrayList;
import java.util.List;

public class UserBO {

	private List<UserModel> userRepo;

	public UserBO() {
		userRepo = new ArrayList<UserModel>();
		userRepo.add(new UserModel(1, "name1", 30));
		userRepo.add(new UserModel(2, "name2", 50));
		userRepo.add(new UserModel(3, "name3", 70));
		userRepo.add(new UserModel(4, "name4", 80));
		userRepo.add(new UserModel(5, "name5", 90));
	}

	public List<UserDTO> getUsers() {
		List<UserDTO> result = new ArrayList<UserDTO>();
		UserDTO userDTO = null;
		for (UserModel user : userRepo) {
			userDTO = new UserDTO();
			userDTO.setName(user.getName());
			userDTO.setScore(user.getScore());
			userDTO.setScoreDesc(getScoreDesc(user.getScore()));
			result.add(userDTO);
		}
		return result;
	}

	private String getScoreDesc(int score) {
		if (score < 60) {
			return "不及格";
		} else if (score < 80) {
			return "及格";
		} else if (score < 90) {
			return "优秀";
		} else if (score <= 100) {
			return "牛逼";
		} else {
			return "成绩不符合规定";
		}
	}
}
